
import request from '@/utils/request'
import { IUserList, IUserStatus, IAddUserParams, IUpdateUserParams, IRoles } from './types/user'

// 获取用户数据列表
export const getUserList = (params: {
    query: string
    pagenum: number
    pagesize: number
 }) => {
  return request<IUserList>({
    method: 'GET',
    url: '/users',
    params
  })
}

// 修改用户状态
export const reqUpdateStatus = (uId: number, type: boolean) => {
  return request<IUserStatus>({
    method: 'put',
    url: `users/${uId}/state/${type}`
  })
}

// 添加用户
export const reqAddUser = (data:IAddUserParams) => {
  return request({
    method: 'post',
    url: 'users',
    data
  })
}

// 编辑用户
export const reqUpdateUser = (id: number | string, data:IUpdateUserParams) => {
  return request({
    method: 'put',
    url: `users/${id}`,
    data
  })
}

// 删除用户
export const reqDeleteUser = (id: number) => {
  return request({
    method: 'delete',
    url: `users/${id}`
  })
}

// 获取所有的角色列表
export const reqRoleList = () => {
  return request<IRoles>({
    method: 'get',
    url: 'roles'
  })
}

// 更新用户的角色
export const reqUpdateRolePower = (id: number, data: {
  rid: number | string
}) => {
  return request({
    method: 'put',
    url: `users/${id}/role`,
    data
  })
}
